package cn.airfei.netty.nio;

import java.nio.IntBuffer;

/**
 * @description:
 * @author: air
 * @create: 2020-12-30 10:55
 */
public class BasicBuffer {
    public static void main(String[] args) {
        // 简单说明buffer的使用
        // 创建一个buffer ,大小为5
        IntBuffer intBuffer=IntBuffer.allocate(10);
        // 向buffer中存放数据
        intBuffer.put(1);
        intBuffer.put(2);
        intBuffer.put(3);
        intBuffer.put(4);
        intBuffer.put(5);

        for (int i=0;i<intBuffer.capacity()/2;i++){
            intBuffer.put(i*3);
        }

        // 读取数据
        intBuffer.flip();
        intBuffer.position(2);
        intBuffer.limit(4);
        intBuffer.clear();
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }

}
